<?php
namespace Home\Controller;
use Think\Controller;
class MessageController extends Controller {

	private $pageSize = 6;
	public function index($pageIndex=1) {
		$Message = D('Message');
		$messages = $Message->relation(true)
			->limit(($pageIndex-1)*($this->pageSize),$this->pageSize)->select();
		//print_r($messages);
		$this->assign('messages',$messages);
		$this->assign('pageIndex',$pageIndex);
		$this->assign('count',($Message->count()+$this->pageSize-1)/$this->pageSize);
		$this->display('index');
	}

	public function create() {
		$Message = D('Message');
		$User = M('User');
		$account = $_SESSION['account'];
		$User->getByAccount($account);
		$Message->user_id = $User->id;
		$Message->content =$_POST['content'];
		$Message->time = date("Y-m-d H:i:s");
		if($Message->add()){
			$this->success("留言成功","../Message/index");
		}
	}

}